﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UCS.Logic;
using UCS.Helpers;
using UCS.Core;

namespace UCS.PacketProcessing
{
    //Packet 24334
    class AvatarProfileMessage : Message
     {
        private Level m_vLevel;

        public AvatarProfileMessage(Client client)
            : base(client)
        {
            SetMessageType(24334);
        }

        public override void Encode()
        {
            List<Byte> pack = new List<Byte>();
            ClientHome ch = new ClientHome(m_vLevel.GetPlayerAvatar().GetId());
            ch.SetHomeJSON(m_vLevel.SaveToJSON());

            pack.AddRange(m_vLevel.GetPlayerAvatar().Encode());
            pack.AddInt32(ch.GetHomeJSON().Length + 4);
            pack.AddInt32(unchecked((int)0xFFFF0000));
            pack.AddRange(ch.GetHomeJSON());

            //byte[] home2 = new byte[] { /*0x00, 0x00, 0x03, 0x55, 0x25, 0x0F, 0x00, 0x00,*/ 0x78, 0x9C, 0x9D, 0x57, 0x4B, 0x6F, 0xE2, 0x30, 0x10, 0xFE, 0x2F, 0x39, 0x67, 0xA5, 0xD8, 0x4E, 0xC2, 0xE3, 0xB8, 0x5D, 0xED, 0x69, 0x4F, 0xDB, 0xD5, 0x5E, 0x2A, 0x64, 0x19, 0xE2, 0x42, 0xB4, 0xC6, 0x8E, 0x12, 0x07, 0x8A, 0xAA, 0xFE, 0xF7, 0x1D, 0xC7, 0x03, 0x24, 0x88, 0xAA, 0x36, 0x8D, 0x0A, 0xF8, 0xF1, 0x8D, 0xE7, 0xF1, 0xCD, 0x64, 0xFC, 0x9E, 0x08, 0x5D, 0xB5, 0xA6, 0xAE, 0xF8, 0x46, 0xD5, 0x52, 0xDB, 0x64, 0x69, 0xDB, 0x5E, 0xA6, 0x89, 0xD8, 0xD8, 0xFA, 0x20, 0xB9, 0x12, 0x27, 0xD3, 0xC3, 0x64, 0x96, 0x26, 0xFE, 0x27, 0xEF, 0xAC, 0xB0, 0x32, 0x59, 0xBE, 0x64, 0xE9, 0xE5, 0x59, 0xA5, 0xC9, 0xBA, 0xAF,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9, 0x20, 0x7F, 0x10, 0xCD, 0x65, 0x7B, 0x05, 0x7E, 0xFC, 0x07, 0xCA, 0xF2, 0x7C, 0x89 };
            //Debugger.WriteLine(Ionic.Zlib.ZlibStream.UncompressString(home2));

            pack.AddRange(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 });

            SetData(pack.ToArray());
        }

        public void SetLevel(Level level)
        {
            m_vLevel = level;
        }
 
    }
}
